﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using LiuYan.Entity;
using LiuYan.Service;

namespace LiuYan.Web.Areas.Admin.Controllers
{
    public class FdController :BaseController
    {
        //
        // GET: /Admin/GoodSort/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Window(int id)
        {
            ViewData["id"] = id;
            return View();
        }
        public string GetList(int pageIndex, int pageCount,string name)
        {
          
            return JsonConvert.SerializeObject(new FdService().GetList(pageIndex, pageCount, name));
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Del(string ids)
        {
            return new BaseService().Dels(ids, "TB_Fd", false);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="sort"></param>
        /// <returns></returns>
        public int Edit(FormCollection form)
        {
            TB_Fd entity = new TB_Fd();
            entity.Id =Convert.ToInt32(form["id"]);
            entity.Name = form["name"];
            entity.Add = form["add"];
            entity.Tell = form["tell"];
            entity.Person = form["person"];
            entity.Date = DateTime.Now;
            entity.Img = form["img"];
            return new FdService().Edit(entity);
        }
        /// <summary>
        /// 获取一条分类数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetOnetData(int id)
        {
           return  JsonConvert.SerializeObject(new BaseService().GetOneData(id, "TB_fd"));
        }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        public string UploadImg()
        {
            HttpFileCollection file = System.Web.HttpContext.Current.Request.Files;
            int num = file.Count;
            string imgPath = "";
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string fileName = file[0].FileName.Split('\\').Last();
            imgPath = "/Content/fdimg/" + Convert.ToInt64(ts.TotalSeconds) + "." + fileName.Split('.').Last();
            string path = Server.MapPath(imgPath);
            file[0].SaveAs(path);
            return "{'status':'1','path':'" + imgPath + "'}";
        }
    }
}
